import { defineStore } from "pinia";
import { ref } from 'vue';
import { req_getServerStrategyTypes } from "~/utils/axios/index.js";

export const useTreeStore = defineStore('treeStore', () => {
    // 这个不用管
    let openTreeIcon = ref(false);
    // 控制器，设置为true即展开
    let openTreeFlag = ref(false);
    let showGroupFlag = ref(false)
    // 需要与分组组件联动的表格ref
    let treeLinkedTableRef = ref(null)
    // 点击分组时，需要刷新表格的分组id的参数
    let treeLinkedTableCategoryId = ref(null)
    // 树形组件选中的check组
    let treeCheckCategoryId = ref(null)
    // 分组组件中获取的设备id
    let treeDeviceId = ref(null)
    // 导入服务器策略时需要的type
    let treeStrategyTypeList = ref(null)
    let treeStrategyType = ref(null)
    // 树形组件ref
    let treeRef = ref(null)
    // 树形目录组件是否展示
    let directoryDialogVModel = ref(false)
    // 系统类型 win or linux
    let osType = ref()
    let osVersion = ref()

    let isShowStrategyDetail = ref(false)
    // 部门树形组件 用户点击勾选复选框时的函数
    const handleCehecChange = (data,node) => {
        treeCheckCategoryId.value = node.checkedKeys.filter(ckecked => {
            return ckecked != '1'
        })
    }
    // 表格用户选择多选框后，部门树形组件节点变为可选择
    const filterNode = (value, data) => {
        data.disabled = value
        if(value){
            return data.flag == !value 
        }else{
            return data.flag == value
        }
    } 
    // 调用这个方法即打开分组组件
    const openTree = () => {
        openTreeIcon.value = openTreeFlag.value = true;
    }

    const getServerStrategyTypeList = async () => {
        const { data: res } = await req_getServerStrategyTypes();
        treeStrategyTypeList.value = res
    }
    
    return{
        openTreeFlag,
        openTreeIcon,
        showGroupFlag,
        treeRef,
        treeLinkedTableRef,
        treeLinkedTableCategoryId,
        treeDeviceId,
        treeStrategyTypeList,
        treeStrategyType,
        isShowStrategyDetail,
        openTree,
        filterNode,
        handleCehecChange,
        getServerStrategyTypeList,
        treeCheckCategoryId,
        directoryDialogVModel,
        osType,
        osVersion
    }
})